home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * C/C++ Header File for FORMULA BUILDER Version 1.0
- * An Advanced Expression Parsing/Evaluation Engine
- * YGB Software, Inc.
- * Copyright (c) 1995, Clayton Collie, All Rights Reserved
- *
- */
-
- #ifndef __FB_H__
- #define __FB_H__
-
- #ifndef _INC_WINDOWS
- #include "windows.h"
- #endif
-
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif // __cplusplus
-
- #define FB_VERSION 0x0100
-
-
- typedef LONG HEXPR; /* expression handle type */
- typedef int FBERROR; /* Formula Builder Error Type */
-
- #define CALLBACK FAR PASCAL _export
- #define FBAPI FAR PASCAL _export
-
-
- #define MAXFUNCPARAMS 16 /* Functions can have up to MAXFUNCPARAMS parameters */
-
-
- /*
- *
- * Definitions of types handled by Formula Builder
- *
- */
- typedef BYTE datatypes;
- typedef BYTE BOOLEAN;
- typedef double FLOAT; /* FormulaBuilder floating point type */
-
- /*
- * Dates are stored as a floating point value whose integer portion represents
- * the number days elapsed since 01/01/001. The time of day, when time functions
- * are implemented, will be represented by the fractional part.
- *
- */
-
- typedef double TFBDate, TFBDATE, FAR *LPFBDATE;
-
- /*
- * Declaration of the internal FB string type - a pointer to a byte-string,
- * a string in which the first byte designates the length, followed by the
- * string data (which is limited to 255 characters). Use the utility routines
- * to deal with this type
- *
- */
- typedef char FBString[256];
- typedef FBString *TFBSTRING, FAR *LPFBSTRING;
-
-
- /* NOTE!!!! the following are NOT contiguous */
-
- #define vtINTEGER 0
- #define vtBOOLEAN 1
- #define vtCHAR 2 /* unused */
- #define vtFLOAT 3
- #define vtSTRING 4
- #define vtPOINTER 5
- #define vtDATE 9
- #define vtBOOL 10
- #define vtANY 11
- #define vtNONE 13
- #define vtTYPECLASH 14
- #define vtTYPEMISMATCH vtTYPECLASH
-
-
- /* General value structure */
-
- typedef struct tagTValueRec {
- BYTE flags;
- BYTE vtype;
- union {
- LONG vInteger;
- BOOLEAN vBoolean;
- FLOAT vFloat; /* double */
- TFBSTRING vpString;
- LPVOID vPointer;
- TFBDATE vDate;
- BOOL vBool;
- }
- } TVALUEREC,TValueRec,*PVALUEREC,FAR *LPVALUEREC;
-
-
-
- /*
- *
- * Error Codes
- *
- */
-
- #define INVALID_VARIABLE -9999 /* Arbitrary but (hopefully) unique - return this from */
-
- // Defines for Error Codes
-
- #define EXPR_SUCCESS 1
- #define EXPR_MISSING_PAREN 2
- #define EXPR_BAD_EXPRESSION 3
- #define EXPR_BAD_ASSIGNMENT 4
- #define EXPR_UNKNOWN_IDENT 5
- #define EXPR_LINE_TOO_LONG 6
- #define EXPR_INVALID_TOKEN 7
- #define EXPR_INVALID_CHAR 8
- #define EXPR_MISSING_PARAM 9
- #define EXPR_TYPE_MISMATCH 10
- #define EXPR_INVALID_NUMBER 11
- #define EXPR_MISSING_VARIABLE 12
- #define EXPR_INVALID_VARIABLE 12
- #define EXPR_INVALID_FUNCTION 13
- #define EXPR_ZERO_DIVISION 14
- #define EXPR_STACK_OVERFLOW 15
- #define EXPR_UNEXPECTED_EOS 16
- #define EXPR_INVALID_DATE 17
- #define EXPR_IDENTIFIER_EXPECTED 18
- #define EXPR_RANGE_ERROR 19
- #define EXPR_DOMAIN_ERROR 20
- #define EXPR_MATH_ERROR 21
- #define EXPR_FP_OVERFLOW 22
- #define EXPR_FP_UNDERFLOW 23
- #define EXPR_INT_OVERFLOW 24
- #define EXPR_INVALID_OP 25
- #define EXPR_VARIABLE_EXPECTED 26
- #define EXPR_MISSING_OPERATOR 27
- #define EXPR_MISSING_OPERAND 28
- #define EXPR_CONSTANT_EXPECTED 29
- #define EXPR_DUPLICATE_IDENT 30
- #define EXPR_SYNTAX_ERROR 31
- #define EXPR_CONVERT_ERROR 32
- #define EXPR_INVALID_TYPE 33
- #define EXPR_INVALID_HANDLE 50
- #define EXPR_INVALID_CALLBACK 51
- #define EXPR_FORMULA_TOO_COMPLEX 54
-
- #define EXPR_INVALID_VARIABLE EXPR_MISSING_VARIABLE
-
-
- /*
- *
- * Callback definitions for variable & field implementation
- *
- */
-
- typedef FBERROR (CALLBACK *TCBKFindVariable)(LPSTR varname,LPBYTE vtype,LONG vardata,LONG CBKData);
-
- typedef FBERROR (CALLBACK *TCBKGetVariable)(LPSTR varname,LPVALUEREC value,LONG vardata,LONG CBKData);
-
- typedef FBERROR (CALLBACK *TCBKSetVariable)(LPSTR varname,TVALUEREC value,LONG vardata,LONG CBKData);
-
- /*
- * function enumeration Callback. See FBEnumFunctions
- */
-
- typedef FBERROR (CALLBACK *TCBKEnumFunctions)(LPSTR vname,BYTE vtype,LPSTR parms,BYTE minPrms,LONG EnumData);
-
- /******************************************************
- *
- * Declarations for external function implementation
- *
- ******************************************************/
-
-
- /*
- * Actual parameter list passed to external function callback
- * The parser engine ensures that these match, in number and
- * type, the prototype specified when the callback was registered
- */
-
- typedef TVALUEREC TActParamList[MAXFUNCPARAMS];
- typedef TActParamList *PActParamList,FAR *LPPARAMLIST;
-
-
- /*::::::::::::::::::::::::::::::::::::::::::::::::::::
- Prototypes for external user-defined functions
- Implemented routine must be exportable
- ::::::::::::::::::::::::::::::::::::::::::::::::::::*/
-
- typedef void (CALLBACK *TCBKExternalFunc)(BYTE paramcount, \
- LPPARAMLIST params, \
- LPVALUEREC retvalue, \
- LPINT errcode, \
- LONG lExprData);
-
-
- /*:::::::::::::::Engine initialization and shutdown:::::::::::::*/
-
- HEXPR FBAPI FBInitExpression(LONG lExprData);
- FBERROR FBAPI FBFreeExpression(HEXPR handle);
-
- /*::::::::::::::::::::: Expression Manipulation ::::::::::::::::*/
-
- FBERROR FBAPI FBSetExpression(HEXPR handle,LPSTR expr);
-
- FBERROR FBAPI FBReparseExpression(HEXPR handle);
-
- FBERROR FBAPI FBClearExpression(HEXPR handle);
-
- FBERROR FBAPI FBGetExpression(HEXPR handle,LPSTR expr,WORD maxlen);
-
-
- /*==========================================================================
- *
- * EXPRESSION EVALUATION ROUTINES
- *
- *=========================================================================*/
-
-
- /* determine the result type of the expression. Returns one of the
- vtXXX constants, vtTYPEMISMATCH for an invalid expression */
-
- FBERROR FBAPI FBGetReturnType(HEXPR handle);
-
- /*
- Evaluate the expression, returning a maximum of maxlen characters
- of the null-terminated string result in the buffer/string pointed to
- by outbuf */
-
-
- FBERROR FBAPI FBEvaluate(HEXPR handle,LPSTR lpszBuf,WORD wBuflen);
-
- /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- Evaluate the expression, returning the result in a TValueRec structure
- FBFreevalue should be used to dispose of any memory associated with value
- when it is no longer needed
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
-
- FBERROR FBAPI FBEvaluatePrim(HEXPR handle,LPVALUEREC value);
-
-
- /* Dispose of any memory associated with a TValueRec structure */
-
- void FBAPI FBFreeValue(LPVALUEREC value);
-
- /*
- *
- *
- *
- */
-
- FBERROR FBAPI FBGetStringResult(HEXPR handle,LPSTR value,WORD maxlen);
- FBERROR FBAPI FBGetFloatResult(HEXPR handle,LPDOUBLE value);
- FBERROR FBAPI FBGetBooleanResult(HEXPR handle,LPBOOL value);
- FBERROR FBAPI FBGetIntResult(HEXPR handle,LPLONG value);
- FBERROR FBAPI FBGetDateResult(HEXPR handle,LPFBDATE value);
-
- /*
- Perform a single operation expression evaluation. This is not the most
- efficient method of evaluation when the expression remains the same */
-
- FBERROR FBAPI FBEvalExpression(LPSTR expr,LPBYTE retType,LPSTR buf,WORD maxlen);
-
- /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- Internal Variable handling routines. NOTE ! If the variable callbacks are
- implemented, the evaluation engine will not see the variables added
- by FBAddvariable
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
-
- /* Add a variable of type Vtype (see vtXXX constants) to the Expression Engine */
-
- FBERROR FBAPI FBAddVariable(HEXPR handle,LPSTR vname,BYTE vtype);
- FBERROR FBAPI FBParseAddVariable(HEXPR handle,LPSTR vname,LPSTR expr);
-
- /*
- * Set the value of variable vname from the string value
- *
- */
-
- FBERROR FBAPI FBSetVarFromString(HEXPR handle,LPSTR vname,LPSTR value);
- FBERROR FBAPI FBSetVariablePrim(HEXPR handle,LPSTR vname,TVALUEREC value);
-
- FBERROR FBAPI FBSetStringVariable(HEXPR handle,LPSTR vname,LPCSTR value);
- FBERROR FBAPI FBSetIntegerVariable(HEXPR handle,LPSTR vname,LONG value);
- FBERROR FBAPI FBSetFloatVariable(HEXPR handle,LPSTR vname,DOUBLE value);
- FBERROR FBAPI FBSetBooleanVariable(HEXPR handle,LPSTR vname,BOOL value);
- FBERROR FBAPI FBSetDateVariable(HEXPR handle,LPSTR vname,TFBDATE value);
-
-
- /*
- * Retrieve the string representation of the value of variable vname
- * into the null terminated string value.
- */
-
- FBERROR FBAPI FBGetVarAsString(HEXPR handle,LPSTR vname,LPSTR value,WORD maxlen);
-
- FBERROR FBAPI FBGetStringVariable(HEXPR handle,LPSTR vname,LPSTR value,WORD maxlen);
- FBERROR FBAPI FBGetIntegerVariable(HEXPR handle,LPSTR vname,LPLONG value);
- FBERROR FBAPI FBGetFloatVariable(HEXPR handle,LPSTR vname,LPDOUBLE value);
- FBERROR FBAPI FBGetBooleanVariable(HEXPR handle,LPSTR vname,LPBOOL value);
- FBERROR FBAPI FBGetDateVariable(HEXPR handle,LPSTR vname,LPFBDATE value);
-
- /*
- * Get a pointer to the data of a variable handled internally by FB
- *
- */
-
- FBERROR FBAPI FBGetVarPtr(HEXPR handle,LPSTR vname,LPBYTE vtype,LPVOID *value);
-
- FBERROR FBAPI FBPeekVariable(HEXPR handle,int vno,LPSTR vname,WORD maxlen,LPVALUEREC value);
-
- FBERROR FBAPI FBPeekVarVB(HEXPR handle,int vno,LPSTR vname,WORD maxnamelen,LPINT vtype,LPSTR value,WORD maxvallen);
-
- FBERROR FBAPI FBFreeVariable(HExpr handle,LPSTR vname);
-
- FBERROR FBAPI FBFreeVariableList(HEXPR handle);
-
- FBERROR FBAPI FBGetVariableCount(HEXPR handle);
-
- /* Error handling */
-
- void FBAPI FBGetErrorString(int iEcode,LPSTR lpszBuf,WORD iBufsz);
-
- FBERROR FBAPI FBGetErrorPos(HEXPR handle,LPINT errpos);
-
- /*==========================================================================
- *
- * CONSTANT HANDLING ROUTINES
- *
- *=========================================================================*/
-
- FBERROR FBAPI FBAddConstantPrim(LPSTR cname,LPVALUEREC value);
- FBERROR FBAPI FBParseAddConst(LPSTR vname,LPSTR expr);
- FBERROR FBAPI FBAddStringConstant(LPSTR cname,LPSTR value);
- FBERROR FBAPI FBAddDateConstant(LPSTR cname,TFBDate value);
- FBERROR FBAPI FBAddNumericConstant(LPSTR cname,double value);
- FBERROR FBAPI FBAddBooleanConstant(LPSTR cname,BOOL value);
- FBERROR FBAPI FBGetConstantPrim(LPSTR cname,LPVALUEREC value);
- FBERROR FBAPI FBFreeConstant(LPSTR cname);
- FBERROR FBAPI FBFreeConstants();
-
- /*==========================================================================
- *
- * CALLBACK ROUTINES
- *
- * Register functions to handle external variables. Setting callbacks overrides
- * the internal variable handling routines. All variables must be handled
- * externally
- *
- *==========================================================================*/
-
- FBERROR FBAPI FBSetVariableCallbacks(HEXPR handle,
- TCBKFindVariable CBKVFind,
- TCBKGetVarValue CBKVGetVal,
- TCBKSetVarValue CBKVSetVal,
- LONG lCBKData);
- //
- /* FBERROR FBAPI FBSetFieldCallbacks(HEXPR handle,
- TCBKFindVariable CBKFFind,
- TCBKGetVarValue CBKFGetVal,
- TCBKSetVarValue CBKFSetVal,
- LONG lCBKData);
- */
-
- /*=======================================================================
- *
- * FUNCTION MANAGEMENT ROUTINES
- *
- *
- *========================================================================*/
-
- /*
- * Returns the number of functions registered with FB
- */
- WORD FBAPI FBGetFunctionCount(void);
-
- /*
- * enumerate through all FormulaBuilder functions, calling fnCBK on
- * each iteration. LParam is passed to the callback on each iteration
- *
- */
-
- FBERROR FBAPI FBEnumFunctions(TCBKEnumFunctions fnCbk,LONG lEnumdata);
-
- /*
- * Register a function with FB
- *
- */
- FBERROR FBAPI FBRegisterFunction(LPSTR fname,
- BYTE returntype,
- LPSTR params,
- int minparms,
- TCBKExternalFunc func);
-
- /*=======================================================================
- *
- * UTILITY ROUTINES
- *
- *======================================================================*/
-
-
- /* Copy up to maxlen chars of an FB string to a null terminated string */
-
- void FBAPI FBStrncpy(LPSTR dest,TFBString source,WORD maxlen);
-
-
- /* Return a copy of the value structure */
- TVALUEREC FBCopyValue(TVALUEREC value);
-
-
- /* Convert a null terminated string to an FB date type */
-
- void FBAPI FBlpzToDate(LPSTR source,LPFBDATE value);
-
- void FBAPI FBDateToLpz(LPSTR dest,TFBDATE date,WORD maxlen);
-
- /* Convert an FB string to an FB date */
-
- void FBAPI FBStringToDate(TFBString source,LPFBDATE value);
-
- /* Convert a null-terminated string to an FB string */
- TBString FBAPI FBStringFromLPZ(LPSTR s);
-
-
- #endif // __cplusplus
-
- #endif // __FB_H_
-